package jp.co.jbuy.action.user;

import java.util.UUID;

import javax.servlet.http.HttpSession;

import jp.co.jbuy.action.BaseAction;
import jp.co.jbuy.util.DataUtil;
import jp.co.jbuy.util.MD5;

public class RegistAction extends BaseAction {

	public static final String PAGE_ID = "regist";

	@Override
	public void action() throws Exception {

		HttpSession session = req_.getSession();

		// 获取验证码
		String sessionCaptcha = String.valueOf(session
				.getAttribute("session_captcha"));
		String requestCaptcha = req_.getParameter("request_captcha");

		// 使用MD5重置验证码
		String captcha = MD5.digestMd5(session.getId() + UUID.randomUUID());
		session.setAttribute("session_captcha", captcha);

		if (!DataUtil.isSame(sessionCaptcha, requestCaptcha)) {
			// TODO 跳转到错误画面
			forward(ShowLoginViewAction.PAGE_URL);
			return;
		}

		// TODO 跳转到注册成功画面
		forward("");

	}

}
